package com.datalinkx.dataserver.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import java.io.IOException;

/**
 * @author 山顶洞人郑某
 * @className SpringBeanFilter.java
 * @date 2025 02 27
 */
@Component
public class SpringBeanFilter implements TypeFilter {
    private final Environment environment;
    @Autowired
    public SpringBeanFilter(org.springframework.core.env.Environment environment) {
        this.environment = environment;
    }
    public final String  COPILOT_PACKAGE = "com.datalinkx.copilot";
    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
        // 如果配置了大模型配置，则加载
        if (metadataReader.getClassMetadata().getClassName().startsWith(COPILOT_PACKAGE) && ObjectUtils.isEmpty(environment.getProperty("llm.embedding"))) {
            return true;
        }
        return false;
    }
}
